package edu.uwm.capstone.diasmart.database;

import android.database.Cursor;

public class ReportingDAO {
	private DatabaseHelper dbh;

	public ReportingDAO(DatabaseHelper databaseHelper) {
		this.dbh = databaseHelper;
	}

	public Cursor getLogBookCursor(int typeId, long subTypeID,
			long minEntryTime, long maxEntryTime) {
		StringBuilder localStringBuilder = new StringBuilder();
		localStringBuilder.append("SELECT ");
		localStringBuilder.append("e._id,");
		localStringBuilder.append("e.entry_time,");
		localStringBuilder.append("e.type_id,");
		localStringBuilder.append("e.sub_type_id,");
		localStringBuilder.append("c._id,");
		localStringBuilder.append("e.value");
		localStringBuilder.append(" FROM entries e,categories c,sub_types s ");
		localStringBuilder.append(" WHERE ");
		localStringBuilder.append("e.type_id=" + typeId);
		localStringBuilder.append(" AND e.sub_type_id=" + subTypeID);
		localStringBuilder.append(" AND e.category_id=c._id");
		localStringBuilder.append(" AND e.sub_type_id=s._id");
		localStringBuilder.append(" AND e.entry_time>=" + minEntryTime);
		localStringBuilder.append(" AND e.entry_time<" + maxEntryTime);
		localStringBuilder.append(" ORDER BY e.entry_time DESC, e._id");
		return this.dbh.getReadableDatabase().rawQuery(
				localStringBuilder.toString(), null);
	}

}
